#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = "HuJiang";

import re;

'''
python 基础练习
'''

# ======== 输入输出 ========
# s = input();
# print(s);

# ======== 数据类型 ========
a = 231;
print("a 的值是 %d, 其类型是 %s" % (a, type(a)));
a = 231.442;
print("a 的值是 %f, 其类型是 %s" % (a, type(a)));
a = True;
print("a 的值是 %s, 其类型是 %s" % (a, type(a)));
a = 4 + 2j;
print("a 的值是 %s, 其类型是 %s" % (a, type(a)));
a = "cdsacdasdcs";
print("a 的值是 %s, 其类型是 %s" % (a, type(a)));
a = ["cdsa", True, None, 12, 23.32, 12];
print("a 的值是 %s, 其类型是 %s" % (a, type(a)));
a = ("cdsa", True, None, 12, 23.32, 12);
print("a 的值是 %s, 其类型是 %s" % (a, type(a)));
a = {"name":"hj","age":18};
print("a 的值是 %s, 其类型是 %s" % (a, type(a)));
a = {"name", "age", "age"};
print("a 的值是 %s, 其类型是 %s" % (a, type(a)));
a = None;
print("a 的值是 %s, 其类型是 %s" % (a, type(a)));

# ======== 运算符 ========
print((34 + 22.33) / 3);
print(5 % 2);
print(5 // 2);
print(True and True);
print(True or False);
print(not False);

# ======== ASCII ========
print(ord("a"));
print(chr(98));

# ======== encode && decode ========
print("cdsac".encode("ASCII"));
print("中文".encode("utf-8"));
print(b'cdsac'.decode("ASCII"));
print(b'\xe4\xb8\xad\xe6\x96\x87'.decode("utf-8"));

# ======== string ========
# "格式化模板" % (args)：模板使用%？进行占位，元祖元素替换模板的占位符
print("Hi %s 你好" % ("hj",));
# * 同学你好，在*学期，你的成绩是*，提升了*%
print("%s同学你好，在%02d学期，你的成绩是%.2f，提升了%.2f%%" % ("hj", 2, 87.237567, 1.12345));
print(len("cdasca"));
print(len("中文"));
print(len("中文".encode("utf-8")));
print("SDddcadsca".lower() == "cdsaca");
print("cdsacda".find("a"));
print("cdacda".replace("a", "-"));

# ======== 正则表达式 ========
print(re.match("a", "hujiang"));
print(re.search("a", "hujiang"));
# 截止5月9日，新冠病毒累计确诊人数234例（其中海外输入77例），累计治愈456例，死亡4例，住院观察56例
pa = "新冠病毒累计确诊人数(\d+)例\(其中海外输入(\d+)例\)，累计治愈(\d+)例，死亡(\d+)例，住院观察(\d+)例";
ta = "截止5月9日，新冠病毒累计确诊人数234例(其中海外输入77例)，累计治愈456例，死亡4例，住院观察56例";
ma = re.search(pa, ta);
if ma:
    print(ma.groups());
    print(ma.group(0));
    print(ma.group(1));
    print(ma.group(2));
pa = '<link rel="canonical" href="(.*?)" />';
ta = '<link rel="canonical" href="https://gitee.com/hujiangyx/clazz" />';
result = re.findall(pa, ta);
print(result);

# ======== list ========
l = ["dsa", 32, 34.44, None, True, 32];
print(l);
# ["index_1", "index_2", ...]
l = list("http://www.sfac.xyz/library/novel/%d" % i for i in range(1, 11));
print(l);
l = list(range(1, 10));
print(l);
l.append(10);
print(l);
l.pop();
print(l);
l.pop(0);
print(l);
l.remove(9);
print(l);
l2 = ["cdas", 33];
l += l2;
print(l);
print(l[0]);

# ======== tuple ========
t = tuple(range(1, 10));
print(t);
t = ("dsa", 32, 34.44, None, True, 32, ["hj", "cdascda"]);
print(t);
t[6][0] = "hujiang";
print(t);

# ======== dict ========
d = {"name":"hj", "age":18, "gender":"male"};
print(d);
print(d.keys());
print(d.values());
print(d["name"]);
print(d.get("name1", "aaa"));
d["aaa"] = "bbb";
print(d);
d2 = {"ccc":"ddd", "eee":"fff"};
print(dict(d, **d2));
d.pop("aaa");
print(d);

# ======== set ========
s = {"name", "age", "gender"};
print(s);
s = set(list(range(1, 10)));
print(s);
s.pop();
print(s);
s.remove(8);
print(s);

# ======== 判断语句、循环语句 ========
age = 19;
if age <= 18:
    print("青年");
elif age > 18 and age <= 60:
    print("中年");
else:
    print("老年");

l = list(range(1, 10));
for i in l:
    print(i);

i = 0;
while i < 10:
    print(i);
    i = i + 1;

a = "study" if age <= 18 else "work";
print(a);

# ======== 变量 ========
_a = "cdsacdas";
__a = "cdscda";
HUMAN_NAME = "cdacdas";
#内建作用于 > 全局作用于 > 闭包作用于 > 局部作用于


if __name__ == '__main__':
    random_list = ["23", "32", "33"]
    ses_list = ["23", "11", "1"]
    holt_list = ["23", "22", "3"]
    print("随机：%s\n霍尔特：%s\n平滑曲线：%s" % (random_list, ses_list, holt_list))

